package com.visikard.request;

import java.net.URLEncoder;

import org.apache.http.HttpStatus;

import com.visikard.application.APIURL;
import com.visikard.net.VkRequestMethod;
import com.visikard.net.VkRestClient;
import com.visikard.system.VKregisterConnects;

public class GiftKardRequest extends BaseRequest {

	public String ringUp(final long merchantId, final long staffId, final long uid, final long transactionId,
			final long storeId, final String amountRedeemed, final String previousBalance, final int isGiftKard,
			final String redeemAddress) {

		VkRestClient rc = new VkRestClient(

		VKregisterConnects.getApiContextPathHttp() + APIURL.VK_GIFTKARDS_REDEEMED);

		rc.addParam("merchantId", merchantId);
		rc.addParam("staffId", staffId);
		rc.addParam("userId", uid);
		rc.addParam("transactionId", transactionId);
		rc.addParam("storeId", storeId);
		rc.addParam("prevBalance", previousBalance);
		rc.addParam("amountRedeem", amountRedeemed);
		rc.addParam("isGiftKard", isGiftKard);
		rc.addParam("redeemAddr", redeemAddress);

		rc.execute(VkRequestMethod.POST);
		if (rc.getResponseCode() != HttpStatus.SC_OK) {
			return rc.getErrorMessage();
		}

		return rc.getResponse();
	}

	public String getGiftKard(long merchantId, String redeemedCode) throws Exception {

		VkRestClient rc = new VkRestClient(VKregisterConnects.getApiContextPathHttp()
				+ String.format(APIURL.VK_GIFTKARDS_GET, merchantId, URLEncoder.encode(redeemedCode, "UTF-8")));

		rc.execute(VkRequestMethod.GET);
		if (rc.getResponseCode() != HttpStatus.SC_OK) {
			return rc.getErrorMessage();
		}

		return rc.getResponse();
	}

}
